package com.pty.mercuryservice.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * Created by pty on 2017/12/25
 */
@Configuration
public class SenderConfig {

    // Direct
    @Bean
    public Queue queue() {
        return new Queue("queue");
    }

    @Bean
    public Queue queueBean() {
        return new Queue("queueBean");
    }

    // Topic
    @Bean(name = "message")
    public Queue queueMessage() {
        return new Queue("topic.message");
    }

    @Bean(name = "messages")
    public Queue queueMessages() {
        return new Queue("topic.messages");
    }

    @Bean(name = "messagea")
    public Queue queueTopica() {
        return new Queue("topic.messagea");
    }

    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("exchange");
    }

    @Bean
    Binding bindingExchangeMessage(@Qualifier("message") Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.message");
    }

    @Bean
    Binding bindingExchangeMessages(@Qualifier("messages") Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.messages"); // *代表一个词，#代表一个或多个词
    }

    @Bean
    Binding bindingExchangeMessagea(@Qualifier("messagea") Queue queueMessage, TopicExchange exchange) {
        return BindingBuilder.bind(queueMessage).to(exchange).with("topic.messagea"); // *代表一个词，#代表一个或多个词
    }

}
